<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="入库单别" v-if="judgeShow('tb001')">
				<u-input v-model="dataForm.tb001" disabled></u-input>
			</u-form-item>
			<u-form-item label="入库单号" v-if="judgeShow('tb002')">
				<u-input v-model="dataForm.tb002" disabled></u-input>
			</u-form-item>
			<u-form-item label="单据日期" v-if="judgeShow('tb015')">
				<u-input v-model="dataForm.tb015" disabled></u-input>
			</u-form-item>
			<u-form-item label="工厂编号" v-if="judgeShow('tb010')">
				{{tb010Name}}
			</u-form-item>
			<u-form-item label="移出地" v-if="judgeShow('tb005')">
				{{tb005Name}}
			</u-form-item>
			<u-form-item label="部门名称" v-if="judgeShow('tb023')">
				<jnpf-dep-select v-model="dataForm.tb023" disabled></jnpf-dep-select>
			</u-form-item>
			<u-form-item label="移入地" v-if="judgeShow('tb008')">
				<u-input v-model="dataForm.tb008" disabled></u-input>
			</u-form-item>
			<u-form-item label="移入地名称" v-if="judgeShow('tb009')">
				<u-input v-model="dataForm.tb009" disabled></u-input>
			</u-form-item>

			<u-form-item label="入库日期" v-if="judgeShow('tb003')">
				<u-input v-model="dataForm.tb003" disabled></u-input>
			</u-form-item>
			<u-form-item label="审核者" v-if="judgeShow('tb016')">
				<u-input v-model="dataForm.tb016" disabled></u-input>
			</u-form-item>
			<u-form-item label="签核状态" v-if="judgeShow('tb017')">
				<span v-if="dataForm.tb017==0">待处理</span>
				<span v-if="dataForm.tb017=='S'">传送中</span>
				<span v-if="dataForm.tb017=='1'">签核中</span>
				<span v-if="dataForm.tb017=='2'">退件</span>
				<span v-if="dataForm.tb017=='3'">已核准</span>
				<span v-if="dataForm.tb017=='4'">撤销审核中</span>
				<span v-if="dataForm.tb017=='5'">作废中</span>
				<span v-if="dataForm.tb017=='6'">取消作废中</span>
				<span v-if="dataForm.tb017=='N'">不运行电子签核</span>
			</u-form-item>
			<u-form-item label="币种" v-if="judgeShow('tb021')">
				<u-input v-model="dataForm.tb021" disabled></u-input>
			</u-form-item>
			<u-form-item label="汇率" v-if="judgeShow('tb022')">
				<u-input v-model="dataForm.tb022" disabled></u-input>
			</u-form-item>
			<u-form-item label="税种" v-if="judgeShow('tb019')">
				<span v-if="dataForm.tb019==1">应税内含</span>
				<span v-if="dataForm.tb019==2">应税外加</span>
				<span v-if="dataForm.tb019==3">零税率</span>
				<span v-if="dataForm.tb019==4">免税</span>
				<span v-if="dataForm.tb019==9">不计税</span>
			</u-form-item>
			<u-form-item label="税率" v-if="judgeShow('tb020')">
				<u-input v-model="dataForm.tb020" disabled></u-input>
			</u-form-item>
			<u-form-item label="备注" v-if="judgeShow('tb014')">
				<u-input v-model="dataForm.tb014" disabled></u-input>
			</u-form-item>



			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in dataForm.sfctcList"
					:key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="工单单别" v-if="judgeShow('sfctcList-tc004')">
						<u-input v-model="item.tc004"></u-input>
					</u-form-item>
					<u-form-item label="工单单号" v-if="judgeShow('sfctcList-tc005')">
						<u-input v-model="item.tc005"></u-input>
					</u-form-item>
					<u-form-item label="产品品号" v-if="judgeShow('sfctcList-tc047')">
						<u-input v-model="item.tc047"></u-input>
					</u-form-item>
					<u-form-item label="产品品名" v-if="judgeShow('sfctcList-tc048')">
						<u-input v-model="item.tc048"></u-input>
					</u-form-item>
					<u-form-item label="产品规格" v-if="judgeShow('sfctcList-tc049')">
						<u-input v-model="item.tc049"></u-input>
					</u-form-item>
					<u-form-item label="急料" v-if="judgeShow('sfctcList-tc035')">
						<u-input v-model="item.tc035"></u-input>
					</u-form-item>
					<u-form-item label="单位" v-if="judgeShow('sfctcList-tc010')">
						<u-input v-model="item.tc010"></u-input>
					</u-form-item>
					<u-form-item label="移出工序" v-if="judgeShow('sfctcList-tc006')">
						<u-input v-model="item.tc006"></u-input>
					</u-form-item>
					<u-form-item label="移出工艺" v-if="judgeShow('sfctcList-tc007')">
						<u-input v-model="item.tc007"></u-input>
					</u-form-item>
					<u-form-item label="类型" v-if="judgeShow('sfctcList-tc013')">
						<u-input v-model="item.tc013"></u-input>
					</u-form-item>
					<u-form-item label="数量" v-if="judgeShow('sfctcList-tc036')">
						<u-input v-model="item.tc036"></u-input>
					</u-form-item>
					<u-form-item label="验收日期" v-if="judgeShow('sfctcList-tc038')">
						<u-input v-model="item.tc038"></u-input>
					</u-form-item>
					<u-form-item label="验收数量" v-if="judgeShow('sfctcList-tc014')">
						<u-input v-model="item.tc014"></u-input>
					</u-form-item>
					<u-form-item label="辅单位" v-if="judgeShow('sfctcList-tc050')">
						<u-input v-model="item.tc050"></u-input>
					</u-form-item>
					<u-form-item label="辅单位验收数量" v-if="judgeShow('sfctcList-tc043')">
						<u-input v-model=" item.tc043"></u-input>
					</u-form-item>
					<u-form-item label="报废数量" v-if="judgeShow('sfctcList-tc016')">
						<u-input v-model="item.tc016"></u-input>
					</u-form-item>
					<u-form-item label="破坏数量" v-if="judgeShow('sfctcList-tc052')">
						<u-input v-model="item.tc052"></u-input>
					</u-form-item>
					<u-form-item label="验退数量" v-if="judgeShow('sfctcList-tc037')">
						<u-input v-model="item.tc037"></u-input>
					</u-form-item>
					<u-form-item label="使用人时" v-if="judgeShow('sfctcList-tc020')">
						<u-input v-model="item.tc020"></u-input>
					</u-form-item>
					<u-form-item label="使用机时" v-if="judgeShow('sfctcList-tc021')">
						<u-input v-model="item.tc021"></u-input>
					</u-form-item>
					<u-form-item label="检验状态" v-if="judgeShow('sfctcList-tc039')">
						<u-input v-model="item.tc039"></u-input>
					</u-form-item>
					<u-form-item label="批号" v-if="judgeShow('sfctcList-tc032')">
						<u-input v-model="item.tc032"></u-input>
					</u-form-item>
					<u-form-item label="批号说明" v-if="judgeShow('sfctcList-tc051')">
						<u-input v-model="item.tc051"></u-input>
					</u-form-item>
					<u-form-item label="生产日期" v-if="judgeShow('sfctcList-tc058')">
						<u-input v-model="item.tc058"></u-input>
					</u-form-item>
					<u-form-item label="有效日期" v-if="judgeShow('sfctcList-tc033')">
						<u-input v-model="item.tc033"></u-input>
					</u-form-item>
					<u-form-item label="复检日期" v-if="judgeShow('sfctcList-tc034')">
						<u-input v-model="item.tc034"></u-input>
					</u-form-item>
					<u-form-item label="备注" v-if="judgeShow('sfctcList-tc031')">
						<u-input v-model="item.tc031"></u-input>
					</u-form-item>
					<u-form-item label="预交货日期" v-if="judgeShow('sfctcList-tc024')">
						<u-input v-model="item.tc024"></u-input>
					</u-form-item>
					<u-form-item label="已交数量" v-if="judgeShow('sfctcList-tc025')">
						<u-input v-model="item.tc025"></u-input>
					</u-form-item>
					<u-form-item label="结束" v-if="judgeShow('sfctcList-tc026')">
						<u-input v-model="item.tc026"></u-input>
					</u-form-item>
					<u-form-item label="报废码" v-if="judgeShow('sfctcList-tc054')">
						<u-input v-model="item.tc054"></u-input>
					</u-form-item>
					<u-form-item label="员工编号" v-if="judgeShow('sfctcList-tcd01')">
						<u-input v-model="item.tcd01"></u-input>
					</u-form-item>
					<u-form-item label="班组编号" v-if="judgeShow('sfctcList-tcd02')">
						<u-input v-model="item.tcd02"></u-input>
					</u-form-item>
					<u-form-item label="班组名称" v-if="judgeShow('sfctcList-tc004')">
						<u-input v-model="item.tc004"></u-input>
					</u-form-item>
					<u-form-item label="机器编号" v-if="judgeShow('sfctcList-tc065')">
						<u-input v-model="item.tc065"></u-input>
					</u-form-item>
				</view>
			</view>
		</u-form>
	</view>
</template>

<script>
	import {
		getSfctb
	} from '@/api/workFlow/flowEngine'
	import {
		getDataInterfaceDataInfo,
		getDictionaryDataSelector,
		getDataInterfaceRes,
		getUserAll,
		Interface,
	} from '@/api/common'

	import comMixin from '../mixin'
	import {
		Info,
		Create,
		Update
	} from '@/api/apply/order'
	export default {
		name: 'crmOrder',
		mixins: [comMixin],
		watch: {
			//总需领料量，总未领料量，总领料量
			"dataForm.mocteList": {
				handler(newVal, oldVal) {
					let sumNeed = 0;
					let sumNot = 0;
					let sumTc029 = 0;
					for (let i = 0; i < newVal.length; i++) {
						const e = newVal[i];
						sumNeed += parseFloat(e.ctb_Tb004); //需领用量
						sumNot += parseFloat(e.ctb_Tb004005); //未领用量
						sumTc029 += parseFloat(e.te005); //总领料量
					}
					this.dataForm.sumNeed = sumNeed;
					this.dataForm.sumNot = sumNot;
					this.dataForm.tc029 = sumTc029;
				},
				deep: true,
			},
		},
		data() {
			return {
				dataForm: {},
				id: '',
				dataForm: {},
				udf13Name: [],
				tc011Name: [],
				sourceList: [],
				tb010Name: '',
				tb005Name: '',
				tb017Options: [{
						fullName: "待处理",
						id: "0"
					},
					{
						fullName: "传送中",
						id: "S"
					},
					{
						fullName: "签核中",
						id: "1"
					},
					{
						fullName: "退件",
						id: "2"
					},
					{
						fullName: "已核准",
						id: "3"
					},
					{
						fullName: "撤销审核中",
						id: "4"
					},
					{
						fullName: "作废中",
						id: "5"
					},
					{
						fullName: "取消作废中",
						id: "6"
					},
					{
						fullName: "不运行电子签核",
						id: "N"
					},
				],
			}
		},

		methods: {
			init(data, id, flowFormContentJson) {
				this.setting = data
				console.log('this.setting', this.setting);
				this.id = id
				this.getInfo(data)
			},
			getInfo(data) {
				getSfctb(data.id).then(res => {
					console.log('res', res);
					if (res.code == 200) {
						this.dataForm = res.data
						this.getUser()
						this.getDepartment(this.dataForm.tc004)
						this.gettb005(this.dataForm.tb005)
						this.getPersonnel(this.dataForm.ti007)
						this.getSource()
					}
				})
			},
			judgeShow(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length)
					return true;
				let arr = this.setting.formOperates.filter((o) => o.id === id) || [];
				if (!arr.length) return true;
				let item = arr[0];
				return item.read;
			},
			judgeWrite(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length)
					return false;
				let arr = this.setting.formOperates.filter((o) => o.id === id) || [];
				if (!arr.length) return true;
				let item = arr[0];
				return !item.write;
			},
			getUser() {
				getUserAll().then((res) => {
					this.udf13Name = res.data.filter((item) => this.dataForm.udf13.includes(item.id)).map((item) =>
						item.realName);
					this.tc011Name = res.data.filter((item) => this.dataForm.tc028.includes(item.account)).map((
							item) =>
						item.realName);
				});
			},
			// 获取部门
			getDepartment(id) {
				let interfaceId = '362111000289221189'
				let data = {
					id,
					interfaceId,
					propsValue: 'MB001',
					relationField: 'MB001',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.tb010Name = res.data.JoinStr;
				})
			},
			// 获取部门
			gettb005(id) {
				let interfaceId = '362117292839934533'
				let data = {
					id,
					interfaceId,
					propsValue: 'MD001',
					relationField: 'MD001',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.tb005Name = res.data.JoinStr;
				})
			},
			// 获取人员
			getPersonnel(id) {
				let interfaceId = '438122284524265733'
				let data = {
					id,
					interfaceId,
					propsValue: 'MV001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.ti007Name = res.data.JoinStr;
				})
			},
			// 获取仓库
			getWarehouse(item) {
				let interfaceId = '362114335423601221'
				let data = {
					id: item.tb008,
					interfaceId,
					propsValue: 'MC001',
					relationField: 'MC001',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.$set(item, 'tb008', MC002);
					return res.data.MC002
				})
			},
			getSource() {
				getDictionaryDataSelector("474002610777559109").then(res => {
					this.sourceList = res.data.list.filter((item) => this.dataForm.ta009.includes(item.enCode))
						.map((
								item) =>
							item.fullName);
				});
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},

		}
	}
</script>